#include "stdlib.h"
#include "stdio.h"
#include "assert.h"
#include "err.h"
#include "cintwar.h"
#include "vuvuzela.h"

/* Estructura del TAD */
struct scintwar{
	Bool b;
};

/* Constructor */
cintwar cwa_create(void){
	cintwar cinta;
	cinta = (cintwar)calloc(1,sizeof(struct scintwar));
        if (cinta != NULL) cinta->b = FALSE;
        else errx(EXIT_FAILURE,"No hay memoria disponible");
	return cinta;
}

/* Arrancar la cinta */
void cwa_arr(cintwar cwa){
	assert(cwa != NULL);
        assert(cwa->b == FALSE);
        cwa->b = TRUE;
	printf("graph G {\n");
}

/* Escribe una arista del arbol generador */
void cwa_insarbol(cintwar cwa, tarista ar, vuvuzela vuvu){
	char ** datos;

	assert(cwa != NULL && ar != NULL);
	assert(cwa->b == TRUE);

	datos = vuvu_datos(vuvu);
	printf("\t%s -- %s [label=%d];\n", datos[vertice1(ar)],datos[vertice2(ar)],peso(ar));
}

/* Escribe una arista del grafo restante */
void cwa_insrest(cintwar cwa, tarista ar, vuvuzela vuvu){
	char** datos;
	assert(cwa != NULL && ar != NULL);
	assert(cwa->b == TRUE);

	datos = vuvu_datos(vuvu);
	printf("\t%s -- %s [label=%d,style=dotted];\n",datos[vertice1(ar)],datos[vertice2(ar)],peso(ar));
}

/* Destructor */
cintwar cwa_destroy(cintwar cwa){
	assert(cwa != NULL);
	printf("}\n");
	free(cwa);
        cwa = NULL;
	return cwa;
}
